'''
Created on Jun 12, 2011

@author: Santi
'''
from juegos._contests import Stats
from juegos.tablut import Tablut
class TablutStats(dict):
    ''' Contiene las estadisticas generadas luego de correr un torneo de tablut
    '''  
    def __init__(self):
        self["agent_moves"] = 0
        self["agent_wins"] = 0
        self["agent_draws"] = 0
        self["agent_loses"] = 0
    
    def clear(self):
        for k in self.iterkeys():
            self[k] = 0
    
    def process(self, agents, match_num, move_num, results_or_moves, game):
        ''' Accumulates statistics for each tuple generated by the contest.
        '''
        if move_num is not None:
            self["agent_moves"]+=1
        elif results_or_moves.has_key(Tablut.BLACK_PLAYER):
            if results_or_moves[Tablut.BLACK_PLAYER] > 0:
                self["agent_wins"]+=1
            elif results_or_moves[Tablut.BLACK_PLAYER] == 0:
                self["agent_draws"]+=1
            elif results_or_moves[Tablut.BLACK_PLAYER] < 0:
                self["agent_loses"]+=1
    